-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Intl: Add a new IntlListFormatter class #18519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Intl: Add a new IntlListFormatter class #18519
Conversation
I wouldn't need an RFC if this is a straight forward addition to the existing Intl API which just maps to ICU in a straight forward fashion. I would like to see some smaller improvements, though:
The prefix makes sense to me. Using the |
Hi @TimWolla! Thanks for the suggestions - great ideas! I've pushed a commit that makes the class final and enabled those flags. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more Stub nits. Please do not add PHPDoc comments, unless they allow you to express something that the types themselves cannot.
/** @not-serializable */ | ||
/** @strict-properties */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @not-serializable */ | |
/** @strict-properties */ | |
/** | |
* @not-serializable | |
* @strict-properties | |
*/ |
To make it more clear that these two belong together.
/** @strict-properties */ | ||
final class IntlListFormatter { | ||
|
||
/** @cvalue ULISTFMT_TYPE_OR */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @cvalue ULISTFMT_TYPE_OR */ | |
/** @cvalue ULISTFMT_TYPE_OR */ |
/** @cvalue ULISTFMT_TYPE_OR */ | ||
public const int TYPE_OR = UNKNOWN; | ||
|
||
/** @cvalue ULISTFMT_TYPE_UNITS */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** @cvalue ULISTFMT_TYPE_UNITS */ | |
/** @cvalue ULISTFMT_TYPE_UNITS */ |
/** | ||
* @param string $locale | ||
* @param int $type | ||
* @param int $width | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* @param string $locale | |
* @param int $type | |
* @param int $width | |
*/ |
/** | ||
* @return int | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* @return int | |
*/ |
/** | ||
* @return string | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* @return string | |
*/ |
/** | ||
* @param array $strings | ||
* | ||
* @return string|false | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* @param array $strings | |
* | |
* @return string|false | |
*/ |
* @return string | ||
*/ | ||
public function getErrorMessage(): string {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at EOF.
Thanks for the quick response! I'll make the changes tomorrow. :) |
} | ||
|
||
UErrorCode status = U_ZERO_ERROR; | ||
if (U_ICU_VERSION_MAJOR_NUM >= 67) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#if U_ICU_VERSION_MAJOR_NUM >= 67
UErrorCode status = U_ZERO_ERROR; | ||
if (U_ICU_VERSION_MAJOR_NUM >= 67) { | ||
|
||
LISTFORMATTER_OBJECT(obj) = ulistfmt_openForType(ZSTR_VAL(locale), type, width, &status); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is understood recent releases are more flexible however you do need to check type ... width does not contain silly values and if so throwing a ValueException (zend_argument_value_error with proper argument offset) then adding tests with silly values :)
windows CI failure is related otherwise |
zend_long type = ULISTFMT_TYPE_AND; | ||
zend_long width = ULISTFMT_WIDTH_WIDE; | ||
ZEND_PARSE_PARAMETERS_START(1, 3) | ||
Z_PARAM_STR(locale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to double check locale, e.g. ZSTR_LEN(locale)
needs to be <= INTL_MAX_LOCALE_LEN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to expand on that if its len is 0 then locale can fetch a default from intl_locale_get_default(). Might be simpler if locale is just char * then, just an advice.
This PR adds support for ICU's ListFormatter implementation by implementing a new IntlListFormatter class in PHP.
The class supports ANDs, ORs and UNIT format types. However, they are only available if ICU version is 67 or above. On older versions of ICU, we only allow TYPE_AND and WIDTH_WIDE - we need this because, from what I've understood, the minimum version ICU supported is 57, which was bumped from 50 last year.
The class API is pretty simple:
will display
I have some questions here: